//
//  GHUtils.m
//  GodHorses
//
//  Created by Mac on 2017/11/14.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "TMUtils.h"
#import "OEShopHeaderViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
@implementation TMUtils
+ (void)netWorkMonitorinCanUseWithHandle:(void (^)())handle{
    
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi) {
            if (handle) {
                handle();
            }
        }
    }];
    [manager startMonitoring];
}
+ (UIView*)headerViewWithTitle:(NSString*)title{
    UIView * sectionHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)];
    sectionHeader.backgroundColor = [UIColor whiteColor];
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30, 44)
                                                     text:title
                                                textColor:TM_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    
    [sectionHeader addSubview:titleLable];
    return sectionHeader;
}
+ (UINavigationBar *)navigationBar{
    UINavigationController* nav = (id)[UIApplication sharedApplication].keyWindow.rootViewController.childViewControllers.firstObject;
    return nav.navigationBar;
}
+  (UITabBar *)tabbar{
    UITabBarController* tab = (id)[UIApplication sharedApplication].keyWindow.rootViewController;
    return tab.tabBar;
}
+ (CGFloat)navgationBarBootom{
    if (ios11) {
        UIWindow * window = UIApplication.sharedApplication.delegate.window;
        if (window.safeAreaInsets.bottom) {
            return 88;
        }
    }

    return 64;
}
+ (CGFloat)tabBarTop{
    if (ios11) {
        UIWindow * window = UIApplication.sharedApplication.delegate.window;
        if (window.safeAreaInsets.bottom) {
            return (UIScreenHeight - 83);
        }
    }
    return (UIScreenHeight - 49);
}
//随机颜色
+ (UIColor*)randColor{
    
    UIColor * color = [UIColor colorWithRed:(arc4random()%255)/255.0 green:(arc4random()%255)/255.0 blue:(arc4random()%255)/255.0 alpha:1];
    return color;
}
+ (void)debugSimulationNetWorkWithHadle:(void (^)(NSInteger, NSMutableArray *))handle{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSInteger num = 0.5;
    NSInteger randrom = arc4random()%15;
    NSMutableArray * array = [NSMutableArray new];
    for (NSInteger i = 0; i < randrom; i ++) {
        [array addObject:@(i)];
    }
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(num * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
        if (handle) {
            handle(num,array);
        }
    });
}
+ (void)sendNoJsonRequestWithUrl:(NSString *)url params:(NSDictionary *)params isPost:(BOOL)isPost handle:(void (^)(BOOL, NSString *))handle{
    AFHTTPSessionManager * manger = [AFHTTPSessionManager manager];
    manger.requestSerializer = [AFHTTPRequestSerializer serializer];
    manger.responseSerializer = [AFHTTPResponseSerializer serializer];
    manger.requestSerializer.timeoutInterval = 20;
    manger.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", @"text/javascript",nil];
    if (isPost) {
        [manger POST:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSString * string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
            if (handle) {
                handle(YES,string);
            }
            [SVProgressHUD dismiss];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            if (handle) {
                handle(NO,nil);
            }
            [SVProgressHUD dismiss];
        }];
    }else{
        [manger GET:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSString * string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
            string = [string stringByReplacingOccurrencesOfString:@"showLocation&&showLocation" withString:@""];
            if (handle) {
                handle(YES,string);
            }
            [SVProgressHUD dismiss];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            if (handle) {
                handle(NO,nil);
            }
            [SVProgressHUD dismiss];
        }];
    }
    
    
}
+ (STButton *)titleButtonViewWithTile:(NSString *)title showRightGo:(BOOL)showRightGo handle:(void (^)())handle{
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)
                                                     title:title
                                                titleColor:FirstTextColor
                                                 titleFont:16
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    buyButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    [buyButton setClicAction:^(UIButton *sender) {
        if (handle) {
            handle();
        }
    }];
    UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"我的_16"]];
    imageView.right = UIScreenWidth - 10;
    imageView.centerY = 22;
    imageView.userInteractionEnabled = NO;
    [buyButton addSubview:imageView];
    imageView.hidden = !showRightGo;
    return buyButton;
}
+ (STButton *)titleGreenButtonViewWithTile:(NSString *)title showRightGo:(BOOL)showRightGo handle:(void (^)())handle{
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)
                                                     title:title
                                                titleColor:FirstTextColor
                                                 titleFont:16
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.titleEdgeInsets = UIEdgeInsetsMake(0, 15 + 20 + 10, 0, 0);
    buyButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    [buyButton setClicAction:^(UIButton *sender) {
        if (handle) {
            handle();
        }
    }];
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, 8, 20)];
    greenView.backgroundColor = FirstTextColor;
    [buyButton addSubview:greenView];
    greenView.centerY = buyButton.height/2;
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)
                                                     text:@"更多"
                                                textColor:FirstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentRight];
    [buyButton addSubview:titleLable];
    
    UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"我的_16"]];
    imageView.right = UIScreenWidth - 10;
    imageView.centerY = 22;
    [buyButton addSubview:imageView];
    imageView.hidden = !showRightGo;
    titleLable.right = imageView.left - 10;
    
    if (!showRightGo) {
        imageView.hidden = YES;
        titleLable.hidden = YES;
    }
    return buyButton;
}

+ (UITextField*)textFiledWithLeftImage:(NSString*)leftImage placeHolader:(NSString*)placeHolader  rightView:(UIView*)rightView{
    UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 50)];
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, textFiled.height, textFiled.height)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:leftImage]];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    textFiled.leftView = buyButton;
    textFiled.leftViewMode = UITextFieldViewModeAlways;
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    textFiled.placeholder = placeHolader;
    
    textFiled.rightView = rightView;
    textFiled.rightViewMode = UITextFieldViewModeAlways;
    return textFiled;
}
+ (UITextField*)textFiledWithLeftTitle:(NSString*)leftTitle placeHolader:(NSString*)placeHolader  rightView:(UIView*)rightView{
    UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 50)];
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, textFiled.height, textFiled.height)
                                                     title:leftTitle
                                                titleColor:FirstTextColor
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    textFiled.leftView = buyButton;
    textFiled.leftViewMode = UITextFieldViewModeAlways;
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    buyButton.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    textFiled.placeholder = placeHolader;
    
    textFiled.rightView = rightView;
    textFiled.rightViewMode = UITextFieldViewModeAlways;
    return textFiled;
}
+ (NSURL *)placeHolderImageUrlFromFakeimgPlWithHeight:(NSString *)height witdh:(NSString *)witdh chineseAlsert:(NSString *)chineseAlsert color:(NSString *)color handle:(void (^)(UIImage *))handle{
    NSString * originUrl = @"https://fakeimg.pl";
    if (color.length) {
        originUrl =  [NSString stringWithFormat:@"%@/%@",originUrl,color];
    }
    if (height.floatValue && witdh.floatValue) {
        originUrl =  [NSString stringWithFormat:@"%@/%@x%@",originUrl,witdh,height];
    }else{
        originUrl =  [NSString stringWithFormat:@"%@/%@x%@",originUrl,@"200",@"200"];
    }
    if (chineseAlsert.length) {
        originUrl =  [NSString stringWithFormat:@"%@/?text=%@&font=noto",originUrl,chineseAlsert];
    }
    NSString *strUrl = originUrl;
    NSURL *url = [[NSURL alloc] initWithString:[strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    
    [[SDWebImageManager sharedManager] downloadImageWithURL:url options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (handle) {
            handle(image);
        }
    }];
    return url;
    
}


#pragma mark --七牛
/*
 + (void)sendQiNiuWithImage:(UIImage *)image handle:(void (^)(NSString *))handle{
 // [SVProgressHUD showWithStatus:@"请稍后"];
 NSData * data = UIImageJPEGRepresentation(image, 0.7);
 UIImage *  dealImage = [UIImage imageWithData:data];
 if ([STUserManger defult].qnToken.length) {
 
 
 NSString * filePath = [self getImagePath:dealImage];
 [self sendFileWithFilePath:filePath handle:handle];
 
 }else{
 if (handle) {
 handle(nil);
 }
 }
 }
 + (void)sendQiNiuGifWithData:(NSData *)data handle:(void (^)(NSString *))handle{
 // [SVProgressHUD showWithStatus:@"请稍后"];
 
 if ([STUserManger defult].qnToken.length && data) {
 
 [self sendGifFileWithData:data handle:handle];
 
 }else{
 if (handle) {
 handle(nil);
 }
 }
 }
 + (void)sendFileWithFilePath:(NSString *)path handle:(void (^)(NSString *))handle{
 NSString *token = [STUserManger defult].qnToken;
 QNUploadManager *upManager = [[QNUploadManager alloc] init];
 QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:@"" progressHandler:^(NSString *key, float percent) {
 // NSLog(@"percent == %.2f", percent);
 }
 params:nil
 checkCrc:NO
 cancellationSignal:nil];
 
 NSLog(@"文件filePath = %@",path);
 NSString * keyName = [NSString stringWithFormat:@"iOS%f.mp3",NSDate.date.timeIntervalSince1970];
 [upManager putFile:path key:nil token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
 // NSLog(@"info ===== %@", info);
 //NSLog(@"resp ===== %@", resp);
 if ([resp.allKeys containsObject:@"key"]) {
 NSString * imageUrl = [NSString stringWithFormat:@"%@/%@",STUserManger.defult.qNhead,resp[@"key"]];
 if (handle) {
 handle(imageUrl);
 }
 }
 }
 option:uploadOption];
 }
 + (void)sendGifFileWithData:(NSData*)data handle:(void (^)(NSString *))handle{
 NSString *token = [STUserManger defult].qnToken;
 QNUploadManager *upManager = [[QNUploadManager alloc] init];
 QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:@"image/gif" progressHandler:^(NSString *key, float percent) {
 // NSLog(@"percent == %.2f", percent);
 }
 params:nil
 checkCrc:NO
 cancellationSignal:nil];
 
 
 NSString * keyName = [NSString stringWithFormat:@"iOS%ld.gif",NSDate.date.timeIntervalSince1970];
 [upManager putData:data key:keyName token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
 if ([resp.allKeys containsObject:@"key"]) {
 NSString * imageUrl = [NSString stringWithFormat:@"%@/%@",STUserManger.defult.qNhead,resp[@"key"]];
 if (handle) {
 handle(imageUrl);
 }
 }
 } option:uploadOption];
 
 }
 
 + (void)sendFileWithFilePathFormDateKey:(NSString *)path handle:(void (^)(NSString *))handle{
 NSString *token = [STUserManger defult].qnToken;
 QNUploadManager *upManager = [[QNUploadManager alloc] init];
 
 QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:@"audio/x-mpeg" progressHandler:^(NSString *key, float percent) {
 // NSLog(@"percent == %.2f", percent);
 }
 params:nil
 checkCrc:NO
 cancellationSignal:nil];
 
 NSLog(@"语音filePath = %@",path);
 NSString * keyName = [NSString stringWithFormat:@"iOS%ld.mp3",NSDate.date.timeIntervalSince1970];
 [upManager putFile:path key:keyName token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
 // NSLog(@"info ===== %@", info);
 //NSLog(@"resp ===== %@", resp);
 if ([resp.allKeys containsObject:@"key"]) {
 NSString * imageUrl = [NSString stringWithFormat:@"%@/%@",STUserManger.defult.qNhead,resp[@"key"]];
 if (handle) {
 handle(imageUrl);
 }
 }
 }
 option:uploadOption];
 }
 + (NSString *)getImagePath:(UIImage *)Image {
 NSString *filePath = nil;
 NSData *data = nil;
 if (UIImagePNGRepresentation(Image) == nil) {
 data = UIImageJPEGRepresentation(Image, 0.5);
 } else {
 data = UIImagePNGRepresentation(Image);
 }
 
 //图片保存的路径
 //这里将图片放在沙盒的documents文件夹中
 NSString *DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
 
 //文件管理器
 NSFileManager *fileManager = [NSFileManager defaultManager];
 
 NSInteger num = arc4random()%10000000 + 300;
 //把刚刚图片转换的data对象拷贝至沙盒中
 [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
 NSString *ImagePath = [NSString stringWithFormat:@"/theFirstImage%ld.png",num];
 [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:ImagePath] contents:data attributes:nil];
 
 //得到选择后沙盒中图片的完整路径
 filePath = [[NSString alloc] initWithFormat:@"%@%@", DocumentsPath, ImagePath];
 return filePath;
 }
 + (NSString *)getgifImagePath:(UIImage *)Image {
 NSString *filePath = nil;
 NSData *data = nil;
 if (UIImagePNGRepresentation(Image) == nil) {
 data = UIImageJPEGRepresentation(Image, 0.5);
 } else {
 data = UIImagePNGRepresentation(Image);
 }
 
 //图片保存的路径
 //这里将图片放在沙盒的documents文件夹中
 NSString *DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
 
 //文件管理器
 NSFileManager *fileManager = [NSFileManager defaultManager];
 
 NSInteger num = arc4random()%10000000 + 300;
 //把刚刚图片转换的data对象拷贝至沙盒中
 [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
 NSString *ImagePath = [NSString stringWithFormat:@"/theFirstImage%ld.gif",num];
 [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:ImagePath] contents:data attributes:nil];
 
 //得到选择后沙盒中图片的完整路径
 filePath = [[NSString alloc] initWithFormat:@"%@%@", DocumentsPath, ImagePath];
 return filePath;
 }
 */

#pragma mark --net
+(void)fetchMineUserInfo:(void (^)(OEUserModel *))handle
{
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=home"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 OEUserModel * user = [OEUserModel mj_objectWithKeyValues:modelDic];
                                                 OEUserModel * origin = STUserManger.defult.loginedUser;
                                                 [STUserManger.defult updateUserModel:origin];
                                                 if (handle) {
                                                     handle(user);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
    
}
+ (void)forceUpdateLocation{
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    if (STLocationManger.defult.ipx.length) {
        [paramDic setObject:STLocationManger.defult.ipx forKey:@"ipx"];
    }
    if (STLocationManger.defult.ipy.length) {
        [paramDic setObject:STLocationManger.defult.ipy forKey:@"ipy"];
    }
    
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=currentPosition"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {


                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
+ (void)gotoRuleViewController{
    

    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=Article&a=articleView"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypeGet
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if ([modelDic.allKeys containsObject:@"content"]) {
                                                     NSString * content = [modelDic[@"content"] description];
                                                     STWebViewController * web = [[STWebViewController alloc] initWithH5String:content];
                                                     if ([modelDic.allKeys containsObject:@"title"]) {
                                                         NSString * title = [modelDic[@"title"] description];
                                                         web.forceTitle = title;
                                                         web.progressTintColor = UIColor.whiteColor;
                                                     }
                                                     [UIViewController.new.st_currentNavgationController pushViewController:web animated:YES];
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
#pragma mark --逻辑
+ (void)user_goToSearchVCWithCat_id:(NSString*)cat_id{

}
+ (void)user_goToShopDetailVCWithShop_id:(NSString *)shopc_id{
    if (!shopc_id.length) {
        return;
    }

}
+ (void)gotoShopHeaderWithModel:(OEShopEasyModel *)model{
    OEShopHeaderViewController * vc =  OEShopHeaderViewController.new;
    vc.model = model;
    [vc.st_currentNavgationController pushViewController:vc animated:YES];
}
- (void)viewResbondMonitorMode:(UIView *)view{
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotodebug)];
    tap.numberOfTapsRequired = 5;
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:tap];
}
- (void)gotodebug{
    STNavigationController * nav = [[STNavigationController alloc] initWithRootViewController:STMonitorHomeViewController.new];
    [UIViewController.new.st_currentNavgationController presentViewController:nav animated:YES completion:^{
        
    }];
}
//调用面容指纹支付
+ (void)showFaceOrFingerPayType:(NSString *)type handle:(void (^)(void))successHandle inputPwdHandle:(void (^)(void))inputHandle errorHandle:(void (^)(void))errorHandle{
    if ([UIDevice currentDevice].systemVersion.floatValue<8.0) {
        NSLog(@"ios8.0以后才支持指纹识别");
        return;
    }
    //IOS11之后如果支持faceId也是走同样的逻辑，faceId和TouchId只能选一个
    LAContext *context = [[LAContext alloc] init];
    NSError *error = nil;
    LAPolicy tpolicy =  LAPolicyDeviceOwnerAuthenticationWithBiometrics;
    if (type.integerValue == 1) {
        tpolicy =  LAPolicyDeviceOwnerAuthentication;
    }
    if ([context canEvaluatePolicy:tpolicy error:&error]) {
        //支持 localizedReason为alert弹框的message内容
        [context evaluatePolicy:tpolicy localizedReason:@"Verify that you have Iphone id" reply:^(BOOL success, NSError * _Nullable error) {
            if (success) {
                NSLog(@"验证通过");
                [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                    //用户选择输入密码，切换主线程处理
                    if (successHandle) {
                        successHandle();
                    }
                }];

            } else {
                NSLog(@"验证失败:%@",error.description);
                switch (error.code) {
                    case LAErrorSystemCancel:
                    {
                        NSLog(@"系统取消授权，如其他APP切入");
                        //系统取消授权，如其他APP切入
                        break;
                    }
                    case LAErrorUserCancel:
                    {
                        //用户取消验证Touch ID
                        NSLog(@"用户取消验证Touch ID");
                        break;
                    }
                    case LAErrorAuthenticationFailed:
                    {
                        //授权失败
                        NSLog(@"授权失败");
                        break;
                    }
                    case LAErrorPasscodeNotSet:
                    {
                        //系统未设置密码
                        NSLog(@"系统未设置密码");
                        break;
                    }
                    case LAErrorBiometryNotAvailable:
                    {
                        //设备Touch ID不可用，例如未打开
                        NSLog(@"设备Touch ID不可用，例如未打开");
                        break;
                    }
                    case LAErrorBiometryNotEnrolled:
                    {
                        //设备Touch ID不可用，用户未录入
                        NSLog(@"设备Touch ID不可用，用户未录入");
                        break;
                    }
                    case LAErrorUserFallback:
                    {
                        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                            //用户选择输入密码，切换主线程处理
                            NSLog(@"用户选择输入密码，切换主线程处理");
                            if (inputHandle) {
                                inputHandle();
                            }
                            return ;
                        }];
                        break;
                    }
                    default:
                    {
                        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                            //其他情况，切换主线程处理
                            NSLog(@"其他情况，切换主线程处理");
                        }];
                        break;
                    }
                }
                [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                    if (errorHandle) {
                        errorHandle();
                    }
                    return ;
                }];

            }
        }];
    } else {
        NSLog(@"不支持指纹识别");
        [SVProgressHUD showInfoWithStatus:@"Id verification failed in a short time. Please enter your password"];
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            //用户选择输入密码，切换主线程处理
            NSLog(@"用户选择输入密码，切换主线程处理");
            if (inputHandle) {
                inputHandle();
            }
            return ;
        }];
        NSLog(@"error : %@",error.localizedDescription);
    }
    
}
@end
